package com.atguigu.jxc.service.impl;/*
 *@author 尹凯瑞
 *@date 2020/12/5 8:56
 */

import com.atguigu.jxc.dao.DamageDao;
import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.DamageList;
import com.atguigu.jxc.entity.DamageListGoods;
import com.atguigu.jxc.service.DamageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DamageServiceImpl implements DamageService {
    @Autowired
    private DamageDao damageDao;
    @Transactional
    @Override
    public ServiceVO saveDamageList(DamageList damageList, List<DamageListGoods> damageListGoodsList) {
        //1.保存报损单
        damageDao.saveDamageList(damageList);
        //2.根据报损单号获取报损单
        DamageList damageList1 = damageDao.selectDamageListByNum(damageList.getDamageNumber());
        //3.获取报损单id
        Integer damageListId = damageList1.getDamageListId();
        //4.将damageListId循环插入报损商品表
        for (DamageListGoods damageListGoods : damageListGoodsList) {
            damageListGoods.setDamageListId(damageListId);
        }
        //5.保存报损商品单
        damageDao.saveDamageListGoods(damageListGoodsList);
        return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
    }
    //报损单查询
    @Override
    public Map<String, Object> selectDamageList(String sTime, String eTime) {

        Map<String, Object> map = new HashMap<>();
        List<DamageList> damageLists = damageDao.selectDamageList(sTime,eTime);
        map.put("rows",damageLists);
        return map;
    }
    //报损单商品查询
    @Override
    public Map<String, Object> selectDamageGoodsList(Integer damageListId) {
        Map<String, Object> map = new HashMap<>();
        List<DamageListGoods> damageListGoods = damageDao.selectDamageGoodsList(damageListId);
        map.put("rows",damageListGoods);
        return map;
    }
}
